/**
 * 制作者：九哥
 * 几个主页面跳转
 * 时间：2019-03-01
 * */





/**
 * 引入缓存设置文件 cache.js
 * */
document.write("<script type='text/javascript' src='/h5/js/cache.js'></script>");
//function getTestErr() {
//    //getAppErrMsg(getTest(),'',5000);
//}





$("#toHomePage").on("click",function(){
    window.location.href = '/h5/index.html';
});

$("#toNewsPage").on("click",function(){
    window.location.href = '/h5/news.html';
});

$("#toMessagePage").on("click",function(){
    window.location.href = '/h5/message.html';
});

$("#toOrderPage").on("click",function(){
    window.location.href = '/h5/order.html';
});

$("#toMysetPage").on("click",function(){
    window.location.href = '/h5/myset.html';
});

$("#toWorkPage").on("click",function(){
    window.location.href = '/h5/work.html';
});





/**
 * 员工主体，更换订单图标
 * */
function setFootBtn(){
    var userInfo = cacheGet('userInfo'); //获取用户信息
    //if (userInfo==null || userInfo.type=='undefined') {
    if (userInfo==null) {
        //getErrMsg('没有登录！',''); return;
        $('#toOrderPage').hide();
        $('#toWorkPage').show();
    }
    if (userInfo && userInfo.type==1) {
        $('#toOrderPage').hide();
        $('#toWorkPage').show();
    } else {
        $('#toOrderPage').show();
        $('#toWorkPage').hide();
    }
}





/**
 * URL中，获取指定参数
 * */
function getUrlParam(paramName) {
    var url = document.location.toString();
    var arrObj = url.split("?");
    if (arrObj.length > 1) {
        var arrParam = arrObj[1].split("&");
        var arr;
        for (var i = 0; i < arrParam.length; i++) {
            arr = arrParam[i].split("=");
            if (arr != null && arr[0] == paramName) {
                return decodeURI(arr[1]);
            }
        }
        return "";
    }
    else {
        return "";
    }
}





/**
 * 广告位获取
 * */
function getAds(eleId,genre) {
    var data = {
        app_access:app_access,
        genre:genre
    };
    $.ajax({
        type:'post',
        url:'/api/home/ad',
        data:data,
        success:function(res){
            var h = '';
            if (res.code!=0) {
                h += '<li><img src="'+MC.HOST+'/uploads/20190227/ppt.png"></li>';
                $(eleId).html(h);
                return;
            }
            for(var i=0;i<res.data.length;i++){
                var data = res.data[i];
                h += '<li><img src="';
                h += data.img;
                h += '"';
                if (data.link) {
                    h += ' onclick="window.location.href=\''+data.link+'\';"';
                }
                h += '"></li>';
            }

            $(eleId).html(h);
        },
        error:function(){
            console.log('操作失败！'); return;
        }
    });
}





/**
 * 地址前缀
 * */
function getDomain(){
    return '/api/';
}


/**
 * 判断是否登陆
 * */
function isLogin(){
    var userInfo = cacheGet('userInfo'); //获取用户信息
    if (userInfo==null || userInfo.token=='undefined') {
        window.location.href = '/h5/login/login.html';
    }else{
        return userInfo;
    }
}

///**
// * 本地缓存，获取
// * */
//function cacheGet(key){
//    //return localStorage.getItem(key);
//    return JSON.parse(localStorage.getItem(key));
//}





/**
 * 本地版本号初始化
 * */
function getLocalVersion(){
    var version = cacheDel('appVersion');
    if (!version) {
        version = '1.0.1';
        cacheSet('appVersion',version);
    }
    return version;
}





/**
 * 错误提示框
 * @param msg 提示信息
 * @param url 跳转地址
 * @param t 停留秒数
 * */
function getAppErrMsg(msg,url,t){
    var time, h = '';
    if (t==0 || t=='' || t==null) {
        time = 1000 * 3;
    } else {
        time = t;
    }
    h += '<span>'+msg+'</span>';
    h += '<script>';
    h += 'setTimeout("setErrClose()",'+time+'); function setErrClose(){ $("#errMsg").html("").hide(); }';
    if (url!='') {
        h += 'setTimeout("setJump()",'+time+'); function setJump(){ window.location.href=\''+url+'\'; }';
    }
    h += '</script>';
    $('#errMsg').html(h).show();
}